<?php
/**
 * myValidatorLogin validates username and password pair.
 *
 * @package    symfony
 * @subpackage validator
 * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
 * @version    SVN: $Id$
 */
class myValidatorLogin extends sfValidatorBase
{
  /**
   * Configures the current validator.
   *
   * @param array $options    An array of options
   * @param array $messages   An array of error messages
   *
   * @see sfValidatorBase
   */
  protected function configure($options = array(), $messages = array())
  {
    $this->setMessage('invalid', 'Either login or password are invalid');
  }

  /**
   * @see sfValidatorBase
   */
  protected function doClean($values)
  {
  	$username = $values['username'];
  	$password = $values['password'];
  	
  	$c = new Criteria();
  	$c->add(UserPeer::USERNAME, $username);
  	$user = UserPeer::doSelectOne($c);
  	
    if (($user instanceof User) and ($user->hasPassword($password)))
    {
      return $values;
    }
    else
    {
      throw new sfValidatorError($this, 'invalid', array('values' => $values));
    }
  }
}